package org.sja.log2traffic;

import org.sja.log2traffic.ConfigurationManipulator;
import org.sja.log2traffic.DataCalculator;
import org.sja.log2traffic.dataStructures.ChartPeriodEnum;
import org.sja.log2traffic.dataStructures.ConfigurationEntity;
import org.sja.log2traffic.dataStructures.timeAgregator.LogDataTimeAgregator;
import org.sja.log2traffic.dataStructures.timeAgregator.LogDataTimeAgregatorElement;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;


public class LogDataTimeAgregatorTest {
	
	private LogDataTimeAgregator underTest;
	private DataCalculator dataCalculator = new DataCalculator();
	private ConfigurationEntity configurationFromTo;
	private ConfigurationManipulator configurationManipulator = new ConfigurationManipulator(dataCalculator);
	
	
	@BeforeMethod
	public void setup(){
		configurationFromTo = configurationManipulator.getConfiguration("testResources/log2trafficForTest.properties", "2012-01-01 12:01", "2012-01-03 20:00", ChartPeriodEnum.DAY);
	}
	
	@Test
	public void testLogDataTimeAgregator(){
		
		long test = dataCalculator.stringWithMilisToLong("2012-01-01 16:01:59,999");
		
		underTest = new LogDataTimeAgregator(configurationFromTo, dataCalculator);
		LogDataTimeAgregatorElement logDataTimeAgregatorElement =  (LogDataTimeAgregatorElement)underTest.getLogInfo(test);
		Assert.assertEquals(logDataTimeAgregatorElement.getMajorIndex(), 0);
		Assert.assertEquals(logDataTimeAgregatorElement.getMinorIndex(), 16*60+1);
		
		
		
	}
	
	@Test
	public void testLogDataTimeAgregator2(){
		
		underTest = new LogDataTimeAgregator(configurationFromTo, dataCalculator);
		int maxMajor = underTest.getAmountOfMajors() - 1;
		String resultString = dataCalculator.longToStringWithMilis(dataCalculator.getDateForIndex(underTest, maxMajor));
		Assert.assertEquals(underTest.getAmountOfMajors(), 2);
		Assert.assertEquals(maxMajor, 1);
		Assert.assertEquals(resultString, "2012-01-02 00:00:00,000");
		
		
	}	

}
